// Car类
class Car(val licensePlate: String, val brand: String, val color: String, var price: Double) {
  def drive(): Unit = {
    println("Driving the car.")
  }

  def park(): Unit = {
    println("Parking the car.")
  }

  def refuel(): Unit = {
    println("Refueling the car.")
  }
}

// ElectricCar类，继承自Car类
class ElectricCar(licensePlate: String, brand: String, color: String, price: Double, val batteryCapacity: Double, var range: Double) extends Car(licensePlate, brand, color, price) {
  def charge(): Unit = {
    println("Charging the electric car.")
  }

  override def drive(): Unit = {
    if (range > 0) {
      println("Driving the electric car.")
      range -= 10 // 假设每次行驶消耗10公里电量
    } else {
      println("Cannot drive. Battery is empty.")
    }
  }
}

object Main extends App {
  // 创建一辆普通汽车
  val car = new Car("ABC123", "Toyota", "Red", 25000.0)
  println(s"Car with license plate ${car.licensePlate}, brand ${car.brand}, color ${car.color} and price ${car.price} created.")

  // 创建一辆电动汽车
  val electricCar = new ElectricCar("XYZ456", "Tesla", "Blue", 60000.0, 100.0, 100.0)
  println(s"Electric car with license plate ${electricCar.licensePlate}, brand ${electricCar.brand}, color ${electricCar.color}, price ${electricCar.price}, battery capacity ${electricCar.batteryCapacity} and range ${electricCar.range} created.")

  // 使用普通汽车的方法
  car.drive()
  car.park()
  car.refuel()

  // 使用电动汽车的方法
  electricCar.drive()
  electricCar.charge()
}